-- Shop
-- Created by chengb Nov/10/2015
-- 商店格子

-- 初始化
function initShop(self)
    self.item:removeAllChildren();

    local shopType = self.gridData.shopType;
    if shopType == "ghost_dock" then
        -- 幽灵船坞需要检查
        if not self:checkShowGhostDock() then
            -- 初始化空格
            self:initEmpty();
            return;
        end
    elseif shopType == "church" then
        -- 教堂需要检查
        if not ME.user.bishop then
            -- 初始化空格
            self:initEmpty();
            return;
        end
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            self:updateBuildingVisit();

            local dbase = DungeonShopM.queryShopRule(shopType, "dbase");
            if dbase["need_finish_business"] == 1 and not BraveVSDragonM.hasFinishedBussiness() then
                -- 需要完成商人任务
                alert(getLocStr("suspend_bussiness"));
                return;
            end

            -- 打开商店
            self:openShop();
        end
    end

    -- 商店图标
    local shopIcon = DungeonShopM.queryShopRule(shopType, "icon");
    local icon = getLevelItemIconPath(shopIcon);

    self.icon = ccui.ImageView:create(icon);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
end

-- 播放商店解锁特效
function playShopUnlockEffect(self)
    -- 播放商店解锁的光效
    local function playUnlockEffect()
        playEffect(self, 1261, -18, 140, nil, 1.3);
        playEffect(self, 1262, -20, 120, nil, 1.3);
    end
    performWithDelay(self, playUnlockEffect, 1.0);
end
